<?php
/**
 * Created by PhpStorm.
 * User: lenove
 * Date: 2018/12/13
 * Time: 11:40
 */
include "../config.php";
include  "../Status.php";
if($_SERVER["REQUEST_METHOD"]=="POST"){
    if(isset($_REQUEST["gid"]) && isset($_REQUEST["uid"]) && isset($_REQUEST["num"]) && isset($_REQUEST["price"])){
        $gid = $_REQUEST["gid"];
        $uid = $_REQUEST["uid"];
        $num = $_REQUEST["num"];
        $price = $_REQUEST["price"];
        $totalprice = $num*$price;
        $sql = "UPDATE cart SET g_num =?,total_price=? WHERE uid=? AND gid =?;";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("iiis", $num,$totalprice,$uid,$gid);
        $stmt->execute();
        if($stmt->affected_rows >= 1){
            print_r(json_encode(Status::$update_success));
        }else{
            print_r(json_encode(Status::$update_failure));
        }
    }
}else{
    print_r(json_encode(Status::$request_error));
}